﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import flash.events.*;
    import Engine.Events.*;
    import Engine.Helpers.*;

	/**
	 * 对比GameObject， 多了Item成员，同事绑定资源加载后的处理
	 */
    public class ItemInstance extends GameObject {

        protected var m_item:Item = null;

        public function ItemInstance(_arg1:String){
            if (_arg1){
                this.setItem(Global.gameSettings.getItemByName(_arg1));
            };
        }
        override public function loadObject(_arg1:Object):void{
            super.loadObject(_arg1);
            if (_arg1.itemName){
                this.setItem(Global.gameSettings.getItemByName(_arg1.itemName));
            };
        }
        public function setItem(_arg1:Item):void{
            if (_arg1 != this.m_item){
                if (this.m_item){
                    this.m_item.removeEventListener(LoaderEvent.LOADED, this.onItemImageLoaded);
                };
                this.m_item = _arg1;
                if (this.m_item){
                    this.m_item.addEventListener(LoaderEvent.LOADED, this.onItemImageLoaded);
                    this.updateSize();
                };
                setDisplayObjectDirty(true);
            };
        }
        protected function updateSize():void{
            if (this.isRotated()){
                m_size = new Vector3(this.m_item.sizeY, this.m_item.sizeX);
            } else {
                m_size = new Vector3(this.m_item.sizeX, this.m_item.sizeY);
            };
        }
        protected function isRotated():Boolean{
            return (((m_direction % 2) == 1));
        }
        public function getItem():Item{
            return (this.m_item);
        }
        public function getItemFriendlyName():String{
            var _local1 = "";
            if (this.m_item){
                _local1 = this.m_item.localizedName;
            };
            return (_local1);
        }
        public function getItemName():String{
            var _local1 = "";
            if (this.m_item){
                _local1 = this.m_item.name;
            };
            return (_local1);
        }
        override public function getSaveObject():Object{
            var _local1:Object = super.getSaveObject();
            if (this.m_item){
                _local1.itemName = this.m_item.name;
            } else {
                _local1.itemName = null;
            };
            return (_local1);
        }
        protected function onItemImageLoaded(_arg1:Event):void{
            conditionallyRedraw(true);
        }
        override public function cleanUp():void{
            if (this.m_item){
                this.m_item.removeEventListener(LoaderEvent.LOADED, this.onItemImageLoaded);
                this.m_item = null;
            };
            super.cleanUp();
        }
        public function get isEmptyLot():Boolean{
            return (false);
        }

    }
}//package Classes 
